From e74411be0bfc740c14e2bd2fb9179c8d2708a2cc Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Fri, 19 Jan 2007 14:36:12 +0000 Subject: [PATCH] [LIBXC] Convert between byte-based and 64-bit bitmap arrays. Use this for conversion of the domctl_cpumap. Original patch from Jimi Xenidis Signed-off-by: Keir Fraser --- tools/libxc/xc_domain.c | 23 +++++++++++++---------- tools/libxc/xc_private.c | 31 +++++++++++++++++++++++++++++++ tools/libxc/xc_private.h | 3 +++ 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 3c42aba129..9a156ebba4 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -96,16 +96,19 @@ int xc_vcpu_setaffinity(int xc_handle, { DECLARE_DOMCTL; int ret = -1; + uint8_t local[sizeof (cpumap)]; domctl.cmd = XEN_DOMCTL_setvcpuaffinity; domctl.domain = (domid_t)domid; domctl.u.vcpuaffinity.vcpu = vcpu; - set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, - (uint8_t *)&cpumap); + bitmap_64_to_byte(local, &cpumap, sizeof (cpumap)); + + set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local); + domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8; - if ( lock_pages(&cpumap, sizeof(cpumap)) != 0 ) + if ( lock_pages(local, sizeof(local)) != 0 ) { PERROR("Could not lock memory for Xen hypercall"); goto out; @@ -113,7 +116,7 @@ int xc_vcpu_setaffinity(int xc_handle, ret = do_domctl(xc_handle, &domctl); - unlock_pages(&cpumap, sizeof(cpumap)); + unlock_pages(local, sizeof(local)); out: return ret; @@ -127,16 +130,16 @@ int xc_vcpu_getaffinity(int xc_handle, { DECLARE_DOMCTL; int ret = -1; + uint8_t local[sizeof (cpumap)]; domctl.cmd = XEN_DOMCTL_getvcpuaffinity; domctl.domain = (domid_t)domid; domctl.u.vcpuaffinity.vcpu = vcpu; - set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, - (uint8_t *)cpumap); - domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(*cpumap) * 8; + set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local); + domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8; - if ( lock_pages(cpumap, sizeof(*cpumap)) != 0 ) + if ( lock_pages(local, sizeof(local)) != 0 ) { PERROR("Could not lock memory for Xen hypercall"); goto out; @@ -144,8 +147,8 @@ int xc_vcpu_getaffinity(int xc_handle, ret = do_domctl(xc_handle, &domctl); - unlock_pages(cpumap, sizeof(*cpumap)); - + unlock_pages(local, sizeof (local)); + bitmap_byte_to_64(cpumap, local, sizeof (local)); out: return ret; } diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c index 82e190989c..db3715989a 100644 --- a/tools/libxc/xc_private.c +++ b/tools/libxc/xc_private.c @@ -502,6 +502,37 @@ char *safe_strerror(int errcode) return errbuf; } +void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits) +{ + uint64_t l; + int i, j, b; + + for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) { + l = lp[i]; + for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) { + bp[b+j] = l; + l >>= 8; + nbits -= 8; + } + } +} + +void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits) +{ + uint64_t l; + int i, j, b; + + for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) { + l = 0; + for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) { + l <<= 8; + l |= bp[b+j]; + nbits -= 8; + } + lp[i] = l; + } +} + /* * Local variables: * mode: C diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h index 6dfbdead7a..7705063326 100644 --- a/tools/libxc/xc_private.h +++ b/tools/libxc/xc_private.h @@ -155,4 +155,7 @@ void *map_domain_va_core(unsigned long domfd, int cpu, void *guest_va, int xc_waitdomain_core(int xc_handle, int domain, int *status, int options, vcpu_guest_context_t *ctxt); +void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits); +void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits); + #endif /* __XC_PRIVATE_H__ */ -- 2.30.2